package org.lex.ftp.util.bookmark;

import org.lex.utils.Arrays;

public class Bookmark implements java.io.Serializable {
	private static final long serialVersionUID = -3634642078259771727L;
	private String name = null;
	private Bookmark[] folders = null;
	private Site[] sites = null;

	public Bookmark() {
		this.name = "";
	}

	public Bookmark(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**********
	 * folders
	 *********/
	public void add(Bookmark folder) {
		if (null == folder)
			return;
		if (null == this.folders) {
			this.folders = new Bookmark[1];
			this.folders[0] = folder;
		} else
			this.folders = Arrays.append(folders, folder);
	}

	public void remove(Bookmark folder) {
		if (null == folder || null == this.folders)
			return;
		this.folders = Arrays.removeReferences(folders, folder);
	}

	public int getFolderCount() {
		if (null == folders)
			return 0;
		else
			return folders.length;
	}

	public Bookmark getFolder(int index) {
		if (null == folders || index >= folders.length)
			return null;
		else
			return folders[index];
	}

	/*****************
	 * sites
	 ****************/
	public void add(Site site) {
		if (null == site)
			return;
		if (null == sites) {
			sites = new Site[1];
			sites[0] = site;
		} else
			this.sites = Arrays.append(sites, site);
	}

	public void remove(Site site) {
		if (null == site || null == sites)
			return;
		this.sites = Arrays.removeReferences(sites, site);
	}

	public int getSiteCount() {
		if (null == sites)
			return 0;
		else
			return sites.length;
	}

	public Site getSite(int index) {
		if (null == sites || index >= sites.length)
			return null;
		else
			return sites[index];
	}

	public String toString() {
		return this.name;
	}
}
